import HeroLogic from "../logic/HeroLogic";
import HeroData from "../data/HeroData";

export default class MenaryModel {
    constructor()
    {

    }
    private static _instance:MenaryModel;
    public static get instance() : MenaryModel {
        if (!this._instance)
        {
            this._instance = new MenaryModel();
        }
        return this._instance
    }
    
    private _heroDataList:Array<HeroData> = []
    public get heroDataList() : Array<HeroData> {
        return this._heroDataList
    }
    private initHeroDataList() {
        this._heroDataList = []
        let heroList:Array<object> = HeroLogic.instance.heroList
        for (const key in heroList) {
            if (heroList.hasOwnProperty(key)) {
                const heroObj:object = heroList[key];
                let heroData:HeroData = new HeroData(heroObj);
                this._heroDataList.push(heroData)
            }
        }
    }
    /**
     * onEnterMenary
     */
    public onEnterMenary(callFunc:Function) {
        this.initHeroDataList()
        callFunc()
    }
    /**
     * onLevelUpHero
     */
    public onLevelUpHero(h_id:number,callFunc:Function) {
        HeroLogic.instance.onLevelUpHero(h_id)
        this.initHeroDataList()
        callFunc()
    }
}
